import { getCategoryList } from '@/api/category'
import { ref } from 'vue'

export default function () {
  // 1. get category list
  const isLoadingCategoryList = ref(false)

  const categoryListParams = ref<CategoryListParamsType>({
    // page: 1,
    // limit: 10,
    is_show: '',
    cate_name: '',
  })

  const categoryList = ref<CategoryInfoType[]>([])

  // const categoryCount = ref<number>(0)

  function handleGetCategoryList() {
    isLoadingCategoryList.value = true
    getCategoryList(categoryListParams.value)
      .then(res => {
        categoryList.value = res.list
        // categoryCount.value = res.count
      })
      .finally(() => {
        isLoadingCategoryList.value = false
      })
  }

  return {
    isLoadingCategoryList,
    categoryListParams,
    categoryList,
    // categoryCount,
    handleGetCategoryList,
  }
}
